<?php
/* SVN FILE: $Id: transactions.php 255 2009-12-22 06:45:47Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Bank - View transactions
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 255 $
* @lastrevision $Date: 2009-12-22 06:45:47 +0000 (Tue, 22 Dec 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-12-22 06:45:47 +0000 (Tue, 22 Dec 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/plugins/bank/publicAction/transactions.php $
*/

class plugin_public_bank_transactions extends marketPublicCommand
{
	/**
	 * Main class entry point
	 *
	 * @access	public
	 * @param	object		ipsRegistry reference
	 * @return	void		[Outputs to screen]
	 */
	public function doExecute( ipsRegistry $registry )
	{
		if(!marketRegistry::hasPluginPermission('use'))
		{
			$this->registry->getClass('output')->showError('no_permission');
		}
		
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'bank_bank' ) );
		
		$this->request['account_id'] = intval($this->request['account_id']);
		$account = $this->DB->buildAndFetch(array('select'=>'*','from'=>'market_bank_accounts','where'=>"account_id=".$this->request['account_id']));
		
		if(!$account || $account['a_mem_id'] != $this->memberData['member_id'])
		{
			$this->registry->getClass('output')->showError('no_permission');
		}
		
		$account['accountID'] = bankPluginFunctions::getBankAccountID($account);
		$this->request['st'] = intval($this->request['st']);
		$LIMIT = 50;
		
		$transactions = array();
		$this->DB->build(array(
								'select'	=> '*',
								'from'		=> 'market_bank_transactions',
								'calcRows'	=> TRUE,
								'where'		=> "l_account_id='".$account['accountID']."'",
								'order'		=> 'l_timestamp DESC',
								'limit'		=> array($this->request['st'],$LIMIT)
						)	);
		$q = $this->DB->execute();
		$total = $this->DB->fetchCalculatedRows();
		while($transaction = $this->DB->fetch($q))
		{
			$transactions[] = $transaction;
		}
		
		$pages = $this->registry->output->generatePagination( array( 'totalItems'			=> $total,
																	 'itemsPerPage'			=> 20,
																	 'currentStartValue'	=> $this->request['st'],
																	 'baseUrl'				=> 'plugin='.$this->request['plugin'].'&amp;action=transactions&amp;accountID='.$this->request['account_id'],
																	 'dotsSkip'				=> 5,
														)		);
		
		$content = $this->registry->getClass('output')->getTemplate('ibm_plugin_bank')->transactionsList($transactions, $pages);
		
		$template = $this->registry->getClass('output')->getTemplate('ibmarket')->ibmarketHTMLWrapper($content);
		
		$this->registry->getClass('output')->setTitle( $this->settings['market_name'] );
		$this->registry->getClass('output')->addContent( $template );
		
        $this->registry->getClass('output')->sendOutput();
	}
}